package com.appkubes.fintech.admin.application.data.contact.controller;

import com.appkubes.base.core.entity.vo.UserKeyVO;
import com.appkubes.fintech.admin.application.data.contact.service.DataCollectService;
import com.appkubes.fintech.common.response.Response;
import com.appkubes.fintech.core.po.FintechDataContact;
import com.appkubes.fintech.core.po.FintechDataContactExample;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author: Rongjie
 * @Date: 2020/1/9 22:19
 * @Description:
 */
@Slf4j
@Api(tags = "通讯录数据")
@RestController
@RequestMapping("/data/contact")
public class ContactController {
    @Resource
    DataCollectService dataCollectService;

    @ApiOperation("获取联系人信息")
    @GetMapping("/get")
    public Response<List<FintechDataContact>> get(@Valid UserKeyVO userKeyVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return Response.fail("参数检查失败");
        }

        FintechDataContactExample example = new FintechDataContactExample();
        example.createCriteria().andAppKeyEqualTo(userKeyVO.getAppKey())
                .andUserKeyEqualTo(userKeyVO.getUserKey());
        List<FintechDataContact> dataContactList = dataCollectService.getContactDao().selectByExample(example);
        return Response.success(dataContactList);

    }


}
